﻿using Smobiler.Core;
using Smobiler.Core.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using Model;
using FubiManger.Controls;

namespace FubiManger.UI
{
    partial class OrdersForm : Smobiler.Core.Controls.MobileForm
    {
        public OrdersForm() : base()
        {
            //This call is required by the SmobilerForm.
            InitializeComponent();
        }
        /// <summary>
        /// 商户ID
        /// </summary>
        public string merchantid { get; set; }
        /// <summary>
        /// 实时订单
        /// </summary>
        List<ms_order> daylist = new List<ms_order>();
        private void panclose_Press(object sender, EventArgs e)
        {
            this.Close();
        }

        private void OrdersForm_Load(object sender, EventArgs e)
        {
            daylist = orderDal.Querybytoday(merchantid);//今日订单
            Getorder(daylist);//获取订单
        }

        /// <summary>
        /// 获取订单
        /// </summary>
        private void Getorder(List<ms_order> ordlist)
        {
            try
            {
                if (panord.Controls.Count > 0)
                    panord.Controls.Clear();
                panord.Height = ordlist.Count * 120;
                for (int i = 0; i < ordlist.Count; i++)
                {
                    ordercontrol1 con = new ordercontrol1();
                    con.disksn = ordlist[i].orderdisksn;//桌号
                    con.ordsn = ordlist[i].order_sn;//订单号
                    con.ordtime = ordlist[i].add_time;
                    if (ordlist[i].user_tel.Length == 11)
                        con.nickname = ordlist[i].user_tel.Substring(0, 3) + "****" + ordlist[i].user_tel.Substring(7, 4);
                    con.ordid = ordlist[i].id;//编号
                    con.codestatus = ordlist[i].codestatus; //销售状态
                    con.stype = "1";
                    panord.Controls.Add(con);
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.ToString());
            }
        }
        /// <summary>
        /// 今日订单
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnday_Press(object sender, EventArgs e)
        {
            btnday.BorderColor = System.Drawing.Color.FromArgb(43, 140, 255);
            btnyestoday.BorderColor = System.Drawing.Color.Transparent;
            btnall.BorderColor = System.Drawing.Color.Transparent;
            daylist = orderDal.Querybytoday(merchantid);//今日订单
            Getorder(daylist);//获取订单
        }
        /// <summary>
        /// 昨日订单
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnyestoday_Press(object sender, EventArgs e)
        {
            btnyestoday.BorderColor = System.Drawing.Color.FromArgb(43, 140, 255);
            btnday.BorderColor = System.Drawing.Color.Transparent;
            btnall.BorderColor = System.Drawing.Color.Transparent;
            daylist = orderDal.Querybyyestoday(merchantid);//今日订单
            Getorder(daylist);//获取订单
        }
        /// <summary>
        /// 全部订单
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnall_Press(object sender, EventArgs e)
        {
            btnall.BorderColor = System.Drawing.Color.FromArgb(43, 140, 255);
            btnday.BorderColor = System.Drawing.Color.Transparent;
            btnyestoday.BorderColor = System.Drawing.Color.Transparent;
            daylist = orderDal.Querybymerchantid(merchantid);//今日订单
            Getorder(daylist);//获取订单
        }
    }
}